package com.empire.module.spider.controller.app.lotterybasketballmatchsporttery;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.CommonResult;
import com.empire.framework.common.util.object.BeanUtils;
import static com.empire.framework.common.pojo.CommonResult.success;

import com.empire.framework.excel.core.util.ExcelUtils;

import com.empire.framework.apilog.core.annotation.ApiAccessLog;
import static com.empire.framework.apilog.core.enums.OperateTypeEnum.*;

import com.empire.module.spider.controller.app.lotterybasketballmatchsporttery.vo.*;
import com.empire.module.spider.dal.dataobject.lotterybasketballmatchsporttery.LotteryBasketballMatchSportteryDO;
import com.empire.module.spider.service.lotterybasketballmatchsporttery.LotteryBasketballMatchSportteryService;

@Tag(name = "用户 APP - 篮球竞猜")
@RestController
@RequestMapping("/spider/lottery-basketball-match-sporttery")
@Validated
public class AppLotteryBasketballMatchSportteryController {

    @Resource
    private LotteryBasketballMatchSportteryService lotteryBasketballMatchSportteryService;

    @PostMapping("/create")
    @Operation(summary = "创建篮球竞猜")
    public CommonResult<String> createLotteryBasketballMatchSporttery(@Valid @RequestBody AppLotteryBasketballMatchSportterySaveReqVO createReqVO) {
        return success(lotteryBasketballMatchSportteryService.createLotteryBasketballMatchSporttery(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新篮球竞猜")
    public CommonResult<Boolean> updateLotteryBasketballMatchSporttery(@Valid @RequestBody AppLotteryBasketballMatchSportterySaveReqVO updateReqVO) {
        lotteryBasketballMatchSportteryService.updateLotteryBasketballMatchSporttery(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除篮球竞猜")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteLotteryBasketballMatchSporttery(@RequestParam("id") String id) {
        lotteryBasketballMatchSportteryService.deleteLotteryBasketballMatchSporttery(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得篮球竞猜")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppLotteryBasketballMatchSportteryRespVO> getLotteryBasketballMatchSporttery(@RequestParam("id") String id) {
        LotteryBasketballMatchSportteryDO lotteryBasketballMatchSporttery = lotteryBasketballMatchSportteryService.getLotteryBasketballMatchSporttery(id);
        return success(BeanUtils.toBean(lotteryBasketballMatchSporttery, AppLotteryBasketballMatchSportteryRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得篮球竞猜分页")
    public CommonResult<PageResult<AppLotteryBasketballMatchSportteryRespVO>> getLotteryBasketballMatchSportteryPage(@Valid AppLotteryBasketballMatchSportteryPageReqVO pageReqVO) {
        PageResult<LotteryBasketballMatchSportteryDO> pageResult = lotteryBasketballMatchSportteryService.getLotteryBasketballMatchSportteryPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppLotteryBasketballMatchSportteryRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出篮球竞猜 Excel")
    @ApiAccessLog(operateType = EXPORT)
    public void exportLotteryBasketballMatchSportteryExcel(@Valid AppLotteryBasketballMatchSportteryPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<LotteryBasketballMatchSportteryDO> list = lotteryBasketballMatchSportteryService.getLotteryBasketballMatchSportteryPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "篮球竞猜.xls", "数据", AppLotteryBasketballMatchSportteryRespVO.class,
                        BeanUtils.toBean(list, AppLotteryBasketballMatchSportteryRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "获得list")
    public CommonResult<List<LotteryBasketballMatchSportteryDO>> getList() {
        List<LotteryBasketballMatchSportteryDO> footballMatchs = lotteryBasketballMatchSportteryService.getList();
        return success(footballMatchs);
    }

}
